﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBUtility;
using System.Data;
using System.Data.OracleClient;

namespace TierApplication
{
    public class TranUtils
    {
        #region 各种编号
        public static string GetProductID()
        {
            StringBuilder strSQL = new StringBuilder();
            strSQL.Append("Select GET_PRODUCTID from dual ");
            DataSet ds = DbHelperOra.Query(strSQL.ToString());
            return ds.Tables[0].Rows[0][0].ToString();
        }

        public static string GetSchoolID()
        {
            StringBuilder strSQL = new StringBuilder();
            strSQL.Append("Select GET_SCHOOLID From Dual ");
            DataSet ds = DbHelperOra.Query(strSQL.ToString());
            return ds.Tables[0].Rows[0][0].ToString();
        }

        public static string GetImpBatchNo()
        {
            StringBuilder strSQL = new StringBuilder();
            strSQL.Append("Select lpad(SEQ_IMPBATCHNO.Nextval, 10, '0') From Dual ");
            DataSet ds = DbHelperOra.Query(strSQL.ToString());
            return ds.Tables[0].Rows[0][0].ToString();
        }

        #endregion

        #region Encrypt&Decrypt
        public static string Encrypt(string svalue)
        {
            StringBuilder strSQL = new StringBuilder();
            strSQL.Append("select cast(pg_encrypt_decrypt.encrypt_3key_mode('" + svalue + "',1) as varchar2(90)) from dual  ");
            DataSet ds = DbHelperOra.Query(strSQL.ToString());
            return ds.Tables[0].Rows[0][0].ToString();
        }

        public static string Decrypt(string svalue)
        {
            StringBuilder strSQL = new StringBuilder();
            strSQL.Append("select pg_encrypt_decrypt.decrypt_3key_mode('" + svalue + "',1) from dual  ");
            DataSet ds = DbHelperOra.Query(strSQL.ToString());
            return ds.Tables[0].Rows[0][0].ToString();
        }
        #endregion

        #region Func
        public static void SP_SEND_EMAIL_TEST(string AC_RECEIVER, ref Int32 ai_result, ref string ac_result)
        {
            OracleParameter[] parameters ={
                                               new OracleParameter("AC_RECEIVER",OracleType.VarChar,60),
                                  new OracleParameter("ai_result",OracleType.Int32),
                                   new OracleParameter("ac_result",OracleType.VarChar,4000)
                                                };
            parameters[0].Value = AC_RECEIVER;
            parameters[0].Direction = ParameterDirection.Input;
            parameters[1].Direction = ParameterDirection.Output;
            parameters[2].Direction = ParameterDirection.Output;
            try
            {
                OracleCommand cmd = DbHelperOra.RunProcedureReturnCammand("SP_SEND_EMAIL_TEST", parameters);
                ai_result = int.Parse(cmd.Parameters["ai_result"].Value.ToString());
                ac_result = cmd.Parameters["ac_result"].Value.ToString();
            }
            catch (Exception e)
            {
                ai_result = -1;
                ac_result = "调用邮件发送过程错误,错误原因为：" + TierService.PageValidate.RemoveChr10And13(e.Message);
            }
        }

        #endregion
    }
}
